package com.zdkj.subway.support.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdkj.common.core.util.R;
import com.zdkj.common.data.mybatis.wrapper.CustomQueryWrapper;
import com.zdkj.common.log.annotation.SysLog;
import com.zdkj.common.security.util.ObjectUtils;
import com.zdkj.subway.support.dto.in.SwParamTicketPriceAreaDTO;
import com.zdkj.subway.support.entity.SwParamTicketPriceArea;
import com.zdkj.subway.support.service.SwParamTicketPriceAreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * 票价收费区段
 *
 * @author cui_com
 * @date 2020-01-15 18:39:06
 */
@RestController
@AllArgsConstructor
@RequestMapping("/swparamticketpricearea")
@Api(value = "swparamticketpricearea", tags = "票价收费区段管理")
public class SwParamTicketPriceAreaController {

    private final SwParamTicketPriceAreaService swParamTicketPriceAreaService;

    /**
     * 细分页查询详
     *
     * @param page                   分页对象
     * @param swParamTicketPriceAreaDTO 票价收费区段
     * @return
     */
    @ApiOperation(value = "细分页查询", notes = "细分页查询")
    @GetMapping("/detail/page")
    public R getSwParamTicketPriceAreaDetailPage(Page page, SwParamTicketPriceAreaDTO swParamTicketPriceAreaDTO) {
        return R.ok(swParamTicketPriceAreaService.queryDetailByPage(page,
                new CustomQueryWrapper(SwParamTicketPriceArea.class)
                        .addDTO(swParamTicketPriceAreaDTO)
                        .init()));
    }

    /**
     * 分页查询
     *
     * @param page                   分页对象
     * @param swParamTicketPriceArea 票价收费区段
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public R getSwParamTicketPriceAreaPage(Page page, SwParamTicketPriceArea swParamTicketPriceArea) {
        return R.ok(swParamTicketPriceAreaService.page(page, Wrappers.query(swParamTicketPriceArea)));
    }


    /**
     * 通过id查询票价收费区段
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    public R getById(@PathVariable("id") Integer id) {
        return R.ok(swParamTicketPriceAreaService.getById(id));
    }

    /**
     * 新增票价收费区段
     *
     * @param swParamTicketPriceArea 票价收费区段
     * @return R
     */
    @ApiOperation(value = "新增票价收费区段", notes = "新增票价收费区段")
    @SysLog("新增票价收费区段")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('support_sw_param_ticket_price_area_add')")
    public R save(@RequestBody SwParamTicketPriceAreaDTO swParamTicketPriceArea) {
        SwParamTicketPriceArea defaultObj =
                ObjectUtils.getDefaultObj(SwParamTicketPriceArea.class);
        BeanUtils.copyProperties(swParamTicketPriceArea, defaultObj);
        return R.ok(swParamTicketPriceAreaService.save(defaultObj));
    }

    /**
     * 修改票价收费区段
     *
     * @param swParamTicketPriceArea 票价收费区段
     * @return R
     */
    @ApiOperation(value = "修改票价收费区段", notes = "修改票价收费区段")
    @SysLog("修改票价收费区段")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('support_sw_param_ticket_price_area_edit')")
    public R updateById(@RequestBody SwParamTicketPriceArea swParamTicketPriceArea) {
        SwParamTicketPriceArea obj = new SwParamTicketPriceArea();
        BeanUtils.copyProperties(swParamTicketPriceArea, obj);
        return R.ok(swParamTicketPriceAreaService.updateById(obj));
    }

    /**
     * 通过id删除票价收费区段
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除票价收费区段", notes = "通过id删除票价收费区段")
    @SysLog("通过id删除票价收费区段")
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('support_sw_param_ticket_price_area_del')")
    public R removeById(@PathVariable Integer id) {
        return R.ok(swParamTicketPriceAreaService.removeById(id));
    }

}
